﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Globalization;
using Tihnut.Web.Timer;
using System.Diagnostics;
//using Pop3;
using System.Collections;
using OpenPOP.POP3;
using OpenPOP.MIMEParser;
using System.Data.SqlClient;

namespace SurveySystem.Core
{
    class SMSPollingAgent : PollingAgent
    {
       
        public SMSPollingAgent() : base("SMSPollingInterval") { }

        protected override void Poll()
        {
            SqlConnection conn = CommonUtils.GetConnection();
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT sender, msg FROM ozekimessagein;", conn);
            SqlDataReader rd = cmd.ExecuteReader();
            while (rd.Read())
            {
                CommunicationUtils.HandleNewSMS(rd.GetString(0), rd.GetString(1));
            }
            rd.Close();
            cmd = new SqlCommand("DELETE FROM ozekimessagein;", conn);
            cmd.ExecuteNonQuery();
            conn.Close();            
        }
    }
}
